//
//  ChatMessage.m
//  DDKelai
//
//  Created by Admin on 15/10/19.
//  Copyright (c) 2015年 chenwenhao. All rights reserved.
//

#import "ChatMessage.h"
#import "ChatConfig.h"

@implementation ChatMessageList

+ (ChatMessageList *)chatMessageListFromData:(NSArray *)list
{
    ChatMessageList *data= [[ChatMessageList alloc] init];
    
    NSArray *tempArr = list;
    
    NSMutableArray *chatMessagegArr = [NSMutableArray new];
    for(NSDictionary *dic in tempArr){
        ChatMessage *tempData = [ChatMessage ChatMessageDataFromDic:dic];
        [chatMessagegArr addObject:tempData];
    }
    
    data.chatMessagegArr = chatMessagegArr;
    return data;
}

@end

@implementation ChatMessage

//将FMResultSet对象转换成ChatMessage对象
+ (ChatMessage *)ChatMessageDataFromDB:(FMResultSet *)rs
{
    ChatMessage *chatMsg = [[ChatMessage alloc] init];
    
    chatMsg.dbId =  objectToString(@([rs longLongIntForColumn:Chat_dbId]));
    
    chatMsg.msgId = [rs stringForColumn:Chat_msgId];
    
    chatMsg.sender = [rs stringForColumn:Chat_sender];
    
    chatMsg.sendTime = [rs stringForColumn:Chat_sendTime];
    
    chatMsg.splitTime = [rs stringForColumn:Chat_splitTime];
    
    chatMsg.msgContent = [rs stringForColumn:Chat_msgContent];
    
    chatMsg.msgUrl = [rs stringForColumn:Chat_msgUrl];
    
    chatMsg.rawPrice = [rs stringForColumn:Chat_rawPrice];
    
    chatMsg.discountPrice = [rs stringForColumn:Chat_discountPrice];
    
    chatMsg.mediaPath = [rs stringForColumn:Chat_mediaPath];
    
    chatMsg.contentPath = [rs stringForColumn:Chat_contentpath];
    
    chatMsg.voiceLength = [rs stringForColumn:Chat_voiceLength];
    
    chatMsg.msgSourceType = [rs intForColumn:Chat_msgSourceType];
    
    chatMsg.messageBodyType = [rs intForColumn:Chat_messageBodyType];

    chatMsg.messageState = [rs intForColumn:Chat_messageState];
    
    chatMsg.mediaStatus = [rs intForColumn:Chat_mediaStatus];

    chatMsg.readStatus = [rs intForColumn:Chat_readStatus];
    
    return chatMsg;
}


//将NSDictionary对象转换成ChatMessage对象
+ (ChatMessage *)ChatMessageDataFromDic:(NSDictionary *)dic
{
    //解析自动回复消息数据
    ChatMessage *chatMsg = [[ChatMessage alloc] init];
    
    chatMsg.msgContent = objectToString(dic[@"title"]);
    
    chatMsg.mediaPath = objectToString(dic[@"proAvatar"]);
    
    chatMsg.msgUrl = objectToString(dic[@"originalUrl"]);
    
    chatMsg.rawPrice = objectToString(dic[@"price"]);
    
    chatMsg.discountPrice = objectToString(dic[@"disPrice"]);
    

    
    return chatMsg;
}

#pragma mark - getter
- (BOOL)senderIsSelf {
    return [_sender isEqualToString:[[UserManager shareInstance] getUserId]];
}


//暂时写死
- (CGFloat)imageHeight {
    return 100;
}
//暂时写死
- (CGFloat)imageWidth {
    return 50;
}


@end
